/**
 * 黑名单操作审计日志模型
 * 记录所有与供应商黑名单相关的操作
 */
module.exports = app => {
  const { INTEGER, STRING, ENUM, DATE } = app.Sequelize;

  return app.model.define('blacklist_audit', {
    operator_id: {
      type: INTEGER,
      allowNull: false,
      comment: '操作用户ID'
    },
    supplier_id: {
      type: INTEGER,
      allowNull: false,
      comment: '供应商ID'
    },
    action: {
      type: ENUM('ADD', 'REMOVE', 'CHECK'),
      allowNull: false,
      comment: '操作类型: ADD-添加, REMOVE-移除, CHECK-检查'
    },
    result: {
      type: ENUM('SUCCESS', 'DENIED', 'ALLOWED'),
      allowNull: false,
      comment: '操作结果: SUCCESS-成功, DENIED-拒绝, ALLOWED-允许'
    },
    ip_address: {
      type: STRING(64),
      allowNull: false,
      comment: '操作IP地址'
    },
    remark: {
      type: STRING(512),
      comment: '操作备注信息'
    },
    created_at: {
      type: DATE,
      defaultValue: app.Sequelize.literal('CURRENT_TIMESTAMP'),
      comment: '操作时间'
    }
  }, {
    tableName: 'blacklist_audit',
    timestamps: false,
    indexes: [
      { fields: ['supplier_id'] },
      { fields: ['operator_id'] },
      { fields: ['created_at'] },
      { fields: ['action', 'result'] }
    ]
  });
};